class MacDashboardConverter

  def convert(output)
    js = ''
    return js if output.nil? || !output.kind_of?(Hash) || output.empty?
    output.each do |key, value|
      js << self.send("convert_#{key}", value)
      js << "\n"
    end
    js
  end
  
  def convert_background(bg)
    "bgImg.src = 'images/#{bg}.png';"
  end
  
  def convert_links(links)
    links.collect do |link|
      %{statusBar.append("<a href='#{link[:url]}' title='#{link[:description]}' onclick='openLink(this)' target='blank'>#{link[:message]}</a>");}
    end.join("\n")
  end
  
  def convert_icons(icons)
    icons.collect do |icon|
      %{statusBar.append("<a href='#{icon[:link]}' title='#{icon[:description]}' onclick='openLink(this)' target='blank'><img class='spinner' src='images/#{icon[:status]}-spinner.gif'/></a>");}
    end.join("\n")
  end
  
  def convert_errors(errors)
    "statusBar.innerHTML = 'ERROR occurred, open log to get more details!<br/>' + statusBar.innerHTML;"
  end
end